package com.zoagroup.funzy.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;


/**
 * The persistent class for the message database table.
 * 
 */
@Entity
public class Message implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name="id_msg", unique=true, nullable=false)
	private Integer idMsg;

	@Column(name="text_msg")
	private String textMsg;

	//bi-directional many-to-one association to TypeMsg
	@ManyToOne(cascade=CascadeType.ALL,fetch=FetchType.LAZY)
	@JoinColumn(name="type_msg")
	private TypeMsg typeMsgBean;

	//bi-directional many-to-one association to User
	@ManyToOne(cascade=CascadeType.ALL)
	@JoinColumn(name="id_user")
	private User user;
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name="creation_date")
	private Date creationDate;
	
	@OneToMany(mappedBy="message", cascade=CascadeType.ALL,fetch=FetchType.LAZY)
	private List<UserMessage> usersWithThisMsg;
	
	public Message() {
	}

	public Integer getIdMsg() {
		return this.idMsg;
	}

	public void setIdMsg(Integer idMsg) {
		this.idMsg = idMsg;
	}

	public String getTextMsg() {
		return this.textMsg;
	}

	public void setTextMsg(String textMsg) {
		this.textMsg = textMsg;
	}

	public TypeMsg getTypeMsgBean() {
		return this.typeMsgBean;
	}

	public void setTypeMsgBean(TypeMsg typeMsgBean) {
		this.typeMsgBean = typeMsgBean;
	}

	public User getUser() {
		return this.user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public Date getCreationDate() {
		return creationDate;
	}

	public void setCreationDate(Date creationDate) {
		this.creationDate = creationDate;
	}

	public List<UserMessage> getUsersWithThisMsg() {
		return usersWithThisMsg;
	}

	public void setUsersWithThisMsg(List<UserMessage> usersWithThisMsg) {
		this.usersWithThisMsg = usersWithThisMsg;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((idMsg == null) ? 0 : idMsg.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Message other = (Message) obj;
		if (idMsg == null) {
			if (other.idMsg != null)
				return false;
		} else if (!idMsg.equals(other.idMsg))
			return false;
		return true;
	}
}